/*
 * Android Runner is a multiplayer GPS game fully written by Xurxo Mendez Perez
 * 
 * Copyright (C) 2009 Xurxo Mendez Perez
 *   
 * This file is part of Android Runner.
 * 
 * Android Runner is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Android Runner is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Android Runner.  If not, see <http://www.gnu.org/licenses/>.
 */

package es.sonxurxo.androidrunner.model.service.game.to;

import es.sonxurxo.androidrunner.model.persistence.message.entity.Message;

/**
 * 
 * @author "Xurxo Mendez Perez"
 *
 */
public class MessageTO {

	public static final int SYSTEM_PLAYER_GETS_ITEM_MESSAGE = Message.SYSTEM_PLAYER_GETS_ITEM_MESSAGE;
	public static final int PLAYER_PERSONAL_MESSAGE = Message.PLAYER_PERSONAL_MESSAGE;
	public static final int PLAYER_BROADCAST_MESSAGE = Message.PLAYER_BROADCAST_MESSAGE;
	public static final int SYSTEM_PLAYER_ABANDONED_MESSAGE = 4;
	
	private long id;
	private String senderLogin;
	private String receiverLogin;
	private String messageBody;
	private int type;
	
	public MessageTO() {}
	
	public MessageTO(Message message) {
		this.id = message.getMessageId();
		this.type = message.getType();
		
		if (message.getSender() == null)
			this.senderLogin = null;
		else
			this.senderLogin = message.getSender().getUserData().getLogin();
		if (message.getReceiver() == null)
			this.receiverLogin = null;
		else
			this.receiverLogin = message.getReceiver().getUserData().getLogin();
		this.messageBody = message.getMessageBody();	
	}
	
	public long getId() {
		return this.id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public MessageTO(String senderLogin, String receiverLogin, String body,
			int type) {
		this.senderLogin = senderLogin;
		this.receiverLogin = receiverLogin;
		this.messageBody = body;
		this.type = type;
	}

	public String getMessageBody() {
		return messageBody;
	}

	public void setMessageBody(String messageBody) {
		this.messageBody = messageBody;
	}

	public String getReceiverLogin() {
		return receiverLogin;
	}

	public void setReceiverLogin(String receiverLogin) {
		this.receiverLogin = receiverLogin;
	}

	public String getSenderLogin() {
		return senderLogin;
	}

	public void setSenderLogin(String senderLogin) {
		this.senderLogin = senderLogin;
	}
	
	public String toString() {
		return new String(
				"\n" + 
				"- MESSAGE : \n" + 
				"- Sender : " + this.senderLogin + "\n" +
				"- Receiver : " + this.receiverLogin + "\n" +
				"- Type : " + this.type + "\n" +
				"- Body : " + this.messageBody + "\n" + 
				"\n\n");
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
}
